home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
fontplot.zip
/
FONT.C
< prev
Wrap
C/C++ Source or Header
|
1992-01-12
|
6KB
|
226 lines
/*
To use these routine you need to do this:
begin
initialize the video mode
LoadFont();
// use LoadString just like printf
LoadString( const char *format [, argument, ...]);
// FontPrint always writes the last string send to LoadString
FontPrint( xpos, ypos, color, FontSize );
close-down graphics mode
end program.
[jec]
Jay Clary
availible on EXEC-PC (ask for it by name)
*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <malloc.h>
#include <string.h>
#include <stdarg.h>
#define BYTE char
#define UBYTE unsigned char
#define WORD int
#define UWORD unsigned int
#define LONG long
#define ULONG unsigned long
UBYTE FontSize; // holds the Y-size of each font character
UBYTE *font; // Pointer to the binary font on disk
char FontFileName[80]; // the disk font file name
char FontString[255]; // holds the next string to plot
void LoadFont( void );
void LoadString( char *, ...);
void FontPrint( int, int, UBYTE, int );
void FontPlot( int, int, int, UBYTE, int );
void LoadFont( void )
{ FILE *f;
if ((font = (UBYTE *) malloc(4096)) == NULL)
cprintf("Allocation Error! font in LoadFont");
if ((f = fopen( FontFileName, "rb" )) == NULL) {
cprintf("Error Opening Font File: %s\r\n", FontFileName);
exit(99);
}
if ( (fread(font, 1, 4096, f) ) != 4096) {
cprintf("Error Loading Font File: %s\r\n", FontFileName);
exit(99);
}
}
void LoadString( char *fmt, ...)
{ va_list argptr;
va_start( argptr, fmt );
vsprintf( FontString, fmt, argptr );
va_end( argptr );
}
void FontPrint( int x, int y, UBYTE c, int fs )
{ int i, x1;
x1 = x;
for (i=0; i < strlen(FontString); i++, x1 += 8)
FontPlot( FontString[i], x1, y, c, fs );
}
/*
The FontPlot was designed for a Trident 8900 chipset. Certain
assumptions are made for the particular project that I am
working on. If you plan on using this routine on a video card
with a Trident chipset in 1024x768x256 mode, it will work fine.
If you use another card in 1024x768x256, all you need change is
the bank-switching code. In any other video mode, you need to
write you own character-plotting routine.
************** WARNING ****************************************
No clipping is performed - add it if you like. In my
situation, I don't require it and I just haven't had
time to add it.
If you need to roll you own -
Font Size is the Y-Size of the characters in the font.
All of the fonts used by these routines are 8 pixels wide
so each line of the character is stored in a single byte.
You must pluck-off each bit, one by one. If the bit is
asserted (a '1' bit) the pixel on the screen is plotted
in the color of your choice
*/
void FontPlot( int index, int x, int y, UBYTE c, int FontSize )
{ int y1;
asm { push ds
lds si, font // Load Font Offset
mov ax, index
mov bx, FontSize // Load the FontSize
mul bx // Multiply the index * FontSize
add ax, si // Add that to the font offset
mov si, ax // Save that in SI
mov ax, 0a000h // point to the video segment
mov es, ax // load the ES with it
mov ax, y // move y-position into AX
mov y1, ax // save a copy in y1
mov cx, FontSize // load CX with FontSize (Y-counter)
}
YLoop:
asm { push cx // save the current Y counter
mov ax, y1 // put video y-line in AX
shl ax, 1 // shift (y % 64) into AH
shl ax, 1 //
/********************************/
/* */
/* Trident 8900 bank-switch */
/* */
/********************************/
mov dx, 3c4h // Trident port address
mov al, 0eh // Switch-Bank function
xor ah, 02 // set proper page
out dx, ax // do-it!
/****************************/
/* */
/* End of bank-switch */
/* */
/****************************/
sub bx, bx // zeor-out BX
mov ax, y1 // move y1 into AX
mov bh, al // Swap low/high registers
shl bx, 1 // shift left 2 times
shl bx, 1 // = 10 shift left
add bx, x // Add in the x offset
mov dl, c // move the color into DL
mov al, ds:[si] // get the font line (byte)
mov cx, 8 // 8 font pixels per byte
}
XLoop:
asm { test al, 0ffh // check if font pixel is set
jns skipit // if it's 0, jump around
mov es:[bx], dl // else move DL to the video pos
}
skipit:
asm { rol al, 1 // rotate around for next font pixel
inc bx // point to next screen byte
loop XLoop // do the next X-pixels
mov ax, y1 // get ready to inc y1
inc ax // do-it
mov y1, ax // save y1
inc si // point to next font line (byte)
pop cx // restore YLoop counter
loop YLoop // do the next Y-line
pop ds // All done, saddle-up & ride
}
}